package gamePackage;

//Imports
import gamePackage.AI;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;


public class DrawPanel extends JPanel implements ActionListener, KeyListener {
	
	static Font font = new Font("Arial", Font.BOLD, 32);
	static Font end = new Font("Arial", Font.BOLD, 128);
	Player player; //Player class object
	Image bg; //Background image variable
	Timer time; //FPS update
	int endCounter = 0;
	 
	//Enemy objects
	AI en1, en2, en3, en4, en5, en6, en7, en8, en9, en10, en11, en12, en13, en14, en15, en16, en17, en18, en19, en20;
	AI en21, en22, en23, en24, en25, en26, en27, en28, en29, en30, en31, en32, en33, en34, en35, en36, en37, en38, en39, en40;
	AI en41, en42, en43, en44, en45, en46, en47, en48, en49, en50;
	
	
	//Constructor
	public DrawPanel() {
		
		player = new Player();
		addKeyListener(new actionKey());
		setFocusable(true); //Allow detect key press movement
		
		//Retrieve background image
		ImageIcon imgGet = new ImageIcon("src/ve_been_watching_gundam_second_season_and_have_fallen_in_manga_anime_desktop_1280x720_wallpaper-194072.png");
		bg = imgGet.getImage();
		
		//Variable for image update
		time = new Timer(5, this);
		time.start();
		
		//Enemy spawn positions
		
		//Mob 1
		en1 = new AI(1150, 75, ("src/Enemy1.png"));
		en2 = new AI(1150, 225, ("src/Enemy1.png"));
		en3 = new AI(1150, 375, ("src/Enemy1.png"));
		
		//Mob 2
		en4 = new AI(1800, 50, ("src/Enemy1.png"));
		en5 = new AI(1800, 250, ("src/Enemy1.png"));
		en6 = new AI(1900, 250, ("src/Enemy1.png"));
		en7 = new AI(1900, 450, ("src/Enemy1.png"));
		
		//Mob 3
		en8 = new AI(2500, 50, ("src/Enemy1.png"));
		en9 = new AI(2500, 250, ("src/Enemy1.png"));
		en10 = new AI(2500, 450, ("src/Enemy1.png"));
		en11 = new AI(3000, 150, ("src/Enemy1.png"));
		en12 = new AI(3000, 350, ("src/Enemy1.png"));
		
		//Mob 4
		en13 = new AI(5500,-1100,("src/Enemy1.png"));
		en14 = new AI(5750,-1150,("src/Enemy1.png"));
		en15 = new AI(6000,-1200,("src/Enemy1.png"));
		en16 = new AI(6250,-1250,("src/Enemy1.png"));
		en17 = new AI(5500,1650,("src/Enemy1.png"));
		en18 = new AI(5750,1700,("src/Enemy1.png"));
		en19 = new AI(6000,1750,("src/Enemy1.png"));
		en20 = new AI(6250,1800,("src/Enemy1.png"));
		
		//Mob 4 part 2
		en21 = new AI(5100,25,("src/Enemy1.png"));
		en22 = new AI(5200,100,("src/Enemy1.png"));
		en23 = new AI(5300,175,("src/Enemy1.png"));
		en24 = new AI(5100,425,("src/Enemy1.png"));
		en25 = new AI(5200,350,("src/Enemy1.png"));
		en26 = new AI(5300,275,("src/Enemy1.png"));
		
		//Final mob 5
		en27 = new AI(4700,125,("src/Enemy1.png"));
		en28 = new AI(4700,325,("src/Enemy1.png"));
		en29 = new AI(6750,25,("src/Enemy1.png"));
		en30 = new AI(6750,225,("src/Enemy1.png"));
		en31 = new AI(6750,425,("src/Enemy1.png"));
		en32 = new AI(7100,50,("src/Enemy1.png"));
		en33 = new AI(7100,400,("src/Enemy1.png"));
		en34 = new AI(7250,150,("src/Enemy1.png"));
		en35 = new AI(7250,300,("src/Enemy1.png"));
		en36 = new AI(7700,225,("src/Enemy1.png"));
		en37 = new AI(7900,150,("src/Enemy1.png"));
		en38 = new AI(7900,300,("src/Enemy1.png"));
		en39 = new AI(8100,75,("src/Enemy1.png"));
		en40 = new AI(8100,375,("src/Enemy1.png"));
		en41 = new AI(8300,75,("src/Enemy1.png"));
		en42 = new AI(8300,375,("src/Enemy1.png"));
		en43 = new AI(8450,150,("src/Enemy1.png"));
		en44 = new AI(8450,300,("src/Enemy1.png"));
		en45 = new AI(8600,175,("src/Enemy1.png"));
		en46 = new AI(8600,275,("src/Enemy1.png"));
		en47 = new AI(8900,175,("src/Enemy1.png"));
		en48 = new AI(9100,175,("src/Enemy1.png"));
		en49 = new AI(9100,275,("src/Enemy1.png"));
		en50 = new AI(8900,275,("src/Enemy1.png"));
		
	} //End constructor
	
	public void actionPerformed(ActionEvent e) { //Action listener repaint method
		
		checkCollisions();
		ArrayList projectiles = Player.proList(); //Get projectile list
		for (int x = 0; x<projectiles.size(); x++) {
			
			Projectile p = (Projectile) projectiles.get(x);
			if (p.pvis() == true) {
				p.move();	
			}
			else {
				projectiles.remove(x); //Remove projectile if visible is set to false
			}
			
		}
		
		if (player.begin == 1) {
			player.move();
			
			//Mob 1
			en1.move(-1,0);
			en2.move(-1,0);
			en3.move(-1,0);
			
			//Mob 2
			en4.move(-1,0.1);
			en5.move(-1,0.1);
			en6.move(-1,-0.1);
			en7.move(-1,-0.1);
			
			//Mob 3
			en8.move(-1,0);
			en9.move(-1,0);
			en10.move(-1,0);
			en11.move(-1.25,0);
			en12.move(-1.25,0);
			
			//Mob 4
			en13.move(-2,0.5);
			en14.move(-2,0.5);
			en15.move(-2,0.5);
			en16.move(-2,0.5);
			en17.move(-2,-0.5);
			en18.move(-2,-0.5);
			en19.move(-2,-0.5);
			en20.move(-2,-0.5);
			
			//Mob 4 part 2
			en21.move(-1.5,0);
			en22.move(-1.5,0);
			en23.move(-1.5,0);
			en24.move(-1.5,0);
			en25.move(-1.5,0);
			en26.move(-1.5,0);
			
			//Final mob 5
			en27.move(-1,0);
			en28.move(-1,0);
			en29.move(-1.5,0);
			en30.move(-1.5,0);
			en31.move(-1.5,0);
			en32.move(-1.5,0);
			en33.move(-1.5,0);
			en34.move(-1.5,0);
			en35.move(-1.5,0);
			en36.move(-1.5,0);
			en37.move(-1.5,0);
			en38.move(-1.5,0);
			en39.move(-1.5,0);
			en40.move(-1.5,0);
			en41.move(-1.5,0);
			en42.move(-1.5,0);
			en43.move(-1.5,0);
			en44.move(-1.5,0);
			en45.move(-1.5,0);
			en46.move(-1.5,0);
			en47.move(-1.5,0);
			en48.move(-1.5,0);
			en49.move(-1.5,0);
			en50.move(-1.5,0);
		}
		
		repaint();
		
	} //End action listener method
	
	//Checks for Collisions
	public void checkCollisions(){
		
		//Mob 1
		Rectangle r1 = en1.getSize(); //Gets the hitbox of the enemies
		Rectangle r2 = en2.getSize();
		Rectangle r3 = en3.getSize();
		
		//Mob 2
		Rectangle r4 = en4.getSize();
		Rectangle r5 = en5.getSize();
		Rectangle r6 = en6.getSize();
		Rectangle r7 = en7.getSize();
		
		//Mob 3
		Rectangle r8 = en8.getSize();
		Rectangle r9 = en9.getSize();
		Rectangle r10 = en10.getSize();
		Rectangle r11 = en11.getSize();
		Rectangle r12 = en12.getSize();
		
		//Mob 4
		Rectangle r13 = en13.getSize();
		Rectangle r14 = en14.getSize();
		Rectangle r15 = en15.getSize();
		Rectangle r16 = en16.getSize();
		Rectangle r17 = en17.getSize();
		Rectangle r18 = en18.getSize();
		Rectangle r19 = en19.getSize();
		Rectangle r20 = en20.getSize();
		
		//Mob 4 part 2
		Rectangle r21 = en21.getSize();
		Rectangle r22 = en22.getSize();
		Rectangle r23 = en23.getSize();
		Rectangle r24 = en24.getSize();
		Rectangle r25 = en25.getSize();
		Rectangle r26 = en26.getSize();

		//Final mob 5
		Rectangle r27 = en27.getSize();
		Rectangle r28 = en28.getSize();
		Rectangle r29 = en29.getSize();
		Rectangle r30 = en30.getSize();
		Rectangle r31 = en31.getSize();
		Rectangle r32 = en32.getSize();
		Rectangle r33 = en33.getSize();
		Rectangle r34 = en34.getSize();
		Rectangle r35 = en35.getSize();
		Rectangle r36 = en36.getSize();
		Rectangle r37 = en37.getSize();
		Rectangle r38 = en38.getSize();
		Rectangle r39 = en39.getSize();
		Rectangle r40 = en40.getSize();
		Rectangle r41 = en41.getSize();
		Rectangle r42 = en42.getSize();
		Rectangle r43 = en43.getSize();
		Rectangle r44 = en44.getSize();
		Rectangle r45 = en45.getSize();
		Rectangle r46 = en46.getSize();
		Rectangle r47 = en47.getSize();
		Rectangle r48 = en48.getSize();
		Rectangle r49 = en49.getSize();
		Rectangle r50 = en50.getSize();
		
		ArrayList projectiles = Player.proList(); //Get projectile list
		for (int x = 0; x<projectiles.size(); x++) {
			
			//Mob 1
			Projectile p = (Projectile) projectiles.get(x);
			Rectangle p1 = p.getSize();
			if (r1.intersects(p1) && en1.isAlive() > 0){ //Checks if enemy is alive; if so then checks if bullet intersects
				en1.aiHealth--; //Makes enemy disappear
				projectiles.remove(x);
				if (en1.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r2.intersects(p1) && en2.isAlive() > 0){ 
				en2.aiHealth--; 
				projectiles.remove(x);
				if (en2.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r3.intersects(p1) && en3.isAlive() > 0){
				en3.aiHealth--;
				projectiles.remove(x);
				if (en3.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			
			//Mob 2
			else if(r4.intersects(p1) && en4.isAlive() > 0){ 
				en4.aiHealth--; 
				projectiles.remove(x);
				if (en4.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r5.intersects(p1) && en5.isAlive() > 0){
				en5.aiHealth--;
				projectiles.remove(x);
				if (en5.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r6.intersects(p1) && en6.isAlive() > 0){ 
				en6.aiHealth--; 
				projectiles.remove(x);
				if (en6.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r7.intersects(p1) && en7.isAlive() > 0){
				en7.aiHealth--;
				projectiles.remove(x);
				if (en7.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			
			//Mob 3
			else if(r8.intersects(p1) && en8.isAlive() > 0){
				en8.aiHealth--;
				projectiles.remove(x);
				if (en8.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r9.intersects(p1) && en9.isAlive() > 0){
				en9.aiHealth--;
				projectiles.remove(x);
				if (en9.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r10.intersects(p1) && en10.isAlive() > 0){
				en10.aiHealth--;
				projectiles.remove(x);
				if (en10.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r11.intersects(p1) && en11.isAlive() > 0){
				en11.aiHealth--;
				projectiles.remove(x);
				if (en11.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r12.intersects(p1) && en12.isAlive() > 0){
				en12.aiHealth--;
				projectiles.remove(x);
				if (en12.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			
			//Mob 4
			else if(r13.intersects(p1) && en13.isAlive() > 0){ 
				en13.aiHealth--; 
				projectiles.remove(x);
				if (en13.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r14.intersects(p1) && en14.isAlive() > 0){
				en14.aiHealth--;
				projectiles.remove(x);
				if (en14.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r15.intersects(p1) && en15.isAlive() > 0){ 
				en15.aiHealth--; 
				projectiles.remove(x);
				if (en15.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r16.intersects(p1) && en16.isAlive() > 0){
				en16.aiHealth--;
				projectiles.remove(x);
				if (en16.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r17.intersects(p1) && en17.isAlive() > 0){ 
				en17.aiHealth--; 
				projectiles.remove(x);
				if (en17.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r18.intersects(p1) && en18.isAlive() > 0){
				en18.aiHealth--;
				projectiles.remove(x);
				if (en18.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r19.intersects(p1) && en19.isAlive() > 0){ 
				en19.aiHealth--; 
				projectiles.remove(x);
				if (en19.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r20.intersects(p1) && en20.isAlive() > 0){
				en20.aiHealth--;
				projectiles.remove(x);
				if (en20.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			
			//Mob 4 part 2
			else if(r21.intersects(p1) && en21.isAlive() > 0){
				en21.aiHealth--;
				projectiles.remove(x);
				if (en21.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r22.intersects(p1) && en22.isAlive() > 0){
				en22.aiHealth--;
				projectiles.remove(x);
				if (en22.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r23.intersects(p1) && en23.isAlive() > 0){
				en23.aiHealth--;
				projectiles.remove(x);
				if (en23.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r24.intersects(p1) && en24.isAlive() > 0){
				en24.aiHealth--;
				projectiles.remove(x);
				if (en24.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r25.intersects(p1) && en25.isAlive() > 0){
				en25.aiHealth--;
				projectiles.remove(x);
				if (en25.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r26.intersects(p1) && en26.isAlive() > 0){
				en26.aiHealth--;
				projectiles.remove(x);
				if (en26.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			
			//Final mob 5
			else if(r27.intersects(p1) && en27.isAlive() > 0){
				en27.aiHealth--;
				projectiles.remove(x);
				if (en27.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r28.intersects(p1) && en28.isAlive() > 0){ 
				en28.aiHealth--; 
				projectiles.remove(x);
				if (en28.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r29.intersects(p1) && en29.isAlive() > 0){
				en29.aiHealth--;
				projectiles.remove(x);
				if (en29.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r30.intersects(p1) && en30.isAlive() > 0){ 
				en30.aiHealth--; 
				projectiles.remove(x);
				if (en30.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r31.intersects(p1) && en31.isAlive() > 0){
				en31.aiHealth--;
				projectiles.remove(x);
				if (en31.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r32.intersects(p1) && en32.isAlive() > 0){ 
				en32.aiHealth--; 
				projectiles.remove(x);
				if (en32.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r33.intersects(p1) && en33.isAlive() > 0){
				en33.aiHealth--;
				projectiles.remove(x);
				if (en33.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r34.intersects(p1) && en34.isAlive() > 0){
				en34.aiHealth--;
				projectiles.remove(x);
				if (en34.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r35.intersects(p1) && en35.isAlive() > 0){ 
				en35.aiHealth--; 
				projectiles.remove(x);
				if (en35.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r36.intersects(p1) && en36.isAlive() > 0){
				en36.aiHealth--;
				projectiles.remove(x);
				if (en36.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r37.intersects(p1) && en37.isAlive() > 0){ 
				en37.aiHealth--; 
				projectiles.remove(x);
				if (en37.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r38.intersects(p1) && en38.isAlive() > 0){
				en38.aiHealth--;
				projectiles.remove(x);
				if (en38.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r39.intersects(p1) && en39.isAlive() > 0){ 
				en39.aiHealth--; 
				projectiles.remove(x);
				if (en39.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r40.intersects(p1) && en40.isAlive() > 0){
				en40.aiHealth--;
				projectiles.remove(x);
				if (en40.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r41.intersects(p1) && en41.isAlive() > 0){
				en41.aiHealth--;
				projectiles.remove(x);
				if (en41.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r42.intersects(p1) && en42.isAlive() > 0){ 
				en42.aiHealth--; 
				projectiles.remove(x);
				if (en42.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r43.intersects(p1) && en43.isAlive() > 0){
				en43.aiHealth--;
				projectiles.remove(x);
				if (en43.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r44.intersects(p1) && en44.isAlive() > 0){
				en44.aiHealth--;
				projectiles.remove(x);
				if (en44.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r45.intersects(p1) && en45.isAlive() > 0){ 
				en45.aiHealth--; 
				projectiles.remove(x);
				if (en45.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r46.intersects(p1) && en46.isAlive() > 0){
				en46.aiHealth--;
				projectiles.remove(x);
				if (en46.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r47.intersects(p1) && en47.isAlive() > 0){ 
				en47.aiHealth--; 
				projectiles.remove(x);
				if (en47.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r48.intersects(p1) && en48.isAlive() > 0){
				en48.aiHealth--;
				projectiles.remove(x);
				if (en48.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r49.intersects(p1) && en49.isAlive() > 0){ 
				en49.aiHealth--; 
				projectiles.remove(x);
				if (en49.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
			else if(r50.intersects(p1) && en50.isAlive() > 0){
				en50.aiHealth--;
				projectiles.remove(x);
				if (en50.aiHealth == 0)
					player.score += 200;
				else
					player.score += 50;
			}
		}
		
		Rectangle prayer = player.getSize(); //Gets the hitbox of the player
		
		//Mob 1
		if (prayer.intersects(r1) && en1.isAlive() > 0 && player.isAlive() > 0) { //Checks if player is touching enemies
			en1.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r2) && en2.isAlive() > 0 && player.isAlive() > 0) {
			en2.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r3) && en3.isAlive() > 0 && player.isAlive() > 0) {
			en3.aiHealth = 0;
			player.health -= 10;
		}
		
		//Mob 2
		else if (prayer.intersects(r4) && en4.isAlive() > 0 && player.isAlive() > 0) {
			en4.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r5) && en5.isAlive() > 0 && player.isAlive() > 0) {
			en5.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r6) && en6.isAlive() > 0 && player.isAlive() > 0) {
			en6.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r7) && en7.isAlive() > 0 && player.isAlive() > 0) {
			en7.aiHealth = 0;
			player.health -= 10;
		}
		
		//Mob 3
		else if (prayer.intersects(r8) && en8.isAlive() > 0 && player.isAlive() > 0) {
			en8.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r9) && en9.isAlive() > 0 && player.isAlive() > 0) {
			en9.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r10) && en10.isAlive() > 0 && player.isAlive() > 0) {
			en10.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r11) && en11.isAlive() > 0 && player.isAlive() > 0) {
			en11.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r12) && en12.isAlive() > 0 && player.isAlive() > 0) {
			en12.aiHealth = 0;
			player.health -= 10;
		}
		
		//Mob 4
		else if (prayer.intersects(r13) && en13.isAlive() > 0 && player.isAlive() > 0) {
			en13.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r14) && en14.isAlive() > 0 && player.isAlive() > 0) {
			en14.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r15) && en15.isAlive() > 0 && player.isAlive() > 0) {
			en15.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r16) && en16.isAlive() > 0 && player.isAlive() > 0) {
			en16.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r17) && en17.isAlive() > 0 && player.isAlive() > 0) {
			en17.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r18) && en18.isAlive() > 0 && player.isAlive() > 0) {
			en18.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r19) && en19.isAlive() > 0 && player.isAlive() > 0) {
			en19.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r20) && en20.isAlive() > 0 && player.isAlive() > 0) {
			en20.aiHealth = 0;
			player.health -= 10;
		}
		
		//Mob 4 part 2
		else if (prayer.intersects(r21) && en21.isAlive() > 0 && player.isAlive() > 0) {
			en21.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r22) && en22.isAlive() > 0 && player.isAlive() > 0) {
			en22.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r23) && en23.isAlive() > 0 && player.isAlive() > 0) {
			en23.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r24) && en24.isAlive() > 0 && player.isAlive() > 0) {
			en24.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r25) && en25.isAlive() > 0 && player.isAlive() > 0) {
			en25.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r26) && en26.isAlive() > 0 && player.isAlive() > 0) {
			en26.aiHealth = 0;
			player.health -= 10;
		}
		
		//Final mob 5
		else if (prayer.intersects(r27) && en27.isAlive() > 0 && player.isAlive() > 0) {
			en27.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r28) && en28.isAlive() > 0 && player.isAlive() > 0) {
			en28.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r29) && en29.isAlive() > 0 && player.isAlive() > 0) {
			en29.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r30) && en30.isAlive() > 0 && player.isAlive() > 0) {
			en30.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r31) && en31.isAlive() > 0 && player.isAlive() > 0) {
			en31.aiHealth = 0; 
			player.health -= 10;
		}
		else if (prayer.intersects(r32) && en32.isAlive() > 0 && player.isAlive() > 0) {
			en32.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r33) && en33.isAlive() > 0 && player.isAlive() > 0) {
			en33.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r34) && en34.isAlive() > 0 && player.isAlive() > 0) {
			en34.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r35) && en35.isAlive() > 0 && player.isAlive() > 0) {
			en35.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r36) && en36.isAlive() > 0 && player.isAlive() > 0) {
			en36.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r37) && en37.isAlive() > 0 && player.isAlive() > 0) {
			en37.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r38) && en38.isAlive() > 0 && player.isAlive() > 0) {
			en38.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r39) && en39.isAlive() > 0 && player.isAlive() > 0) {
			en39.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r40) && en40.isAlive() > 0 && player.isAlive() > 0) {
			en40.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r41) && en41.isAlive() > 0 && player.isAlive() > 0) {
			en41.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r42) && en42.isAlive() > 0 && player.isAlive() > 0) {
			en42.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r43) && en43.isAlive() > 0 && player.isAlive() > 0) {
			en43.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r44) && en44.isAlive() > 0 && player.isAlive() > 0) {
			en44.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r45) && en45.isAlive() > 0 && player.isAlive() > 0) {
			en45.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r46) && en46.isAlive() > 0 && player.isAlive() > 0) {
			en46.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r47) && en47.isAlive() > 0 && player.isAlive() > 0) {
			en47.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r48) && en48.isAlive() > 0 && player.isAlive() > 0) {
			en48.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r49) && en49.isAlive() > 0 && player.isAlive() > 0) {
			en49.aiHealth = 0;
			player.health -= 10;
		}
		else if (prayer.intersects(r50) && en50.isAlive() > 0 && player.isAlive() > 0) {
			en50.aiHealth = 0;
			player.health -= 10;
		}
	}
	
	public void paint(Graphics g) { //2D graphics
		super.paint(g);
		Graphics2D graphics = (Graphics2D) g;
		graphics.drawImage(bg, 0, 0, null); //Background position
		
		//Draw player if alive
		if (player.isAlive() > 0 && player.begin == 1) {
			graphics.drawImage(player.getPlay(), player.playerX(), player.playerY(), null); //Player position	
		}

		//Draw AI if alive
		//Mob 1
		if (player.begin == 1) {
			if (en1.isAlive() > 0 && en1.getX() < 1000)
				graphics.drawImage(en1.getImage(), en1.getX(), en1.getY(), null);
			if (en2.isAlive() > 0 && en2.getX() < 1000)
				graphics.drawImage(en2.getImage(), en2.getX(), en2.getY(), null);
			if (en3.isAlive() > 0 && en3.getX() < 1000)
				graphics.drawImage(en3.getImage(), en3.getX(), en3.getY(), null);
			
			//Mob 2
			if (en4.isAlive() > 0 && en4.getX() < 1000)
				graphics.drawImage(en4.getImage(), en4.getX(), en4.getY(), null);
			if (en5.isAlive() > 0 && en5.getX() < 1000)
				graphics.drawImage(en5.getImage(), en5.getX(), en5.getY(), null);
			if (en6.isAlive() > 0 && en6.getX() < 1000)
				graphics.drawImage(en6.getImage(), en6.getX(), en6.getY(), null);
			if (en7.isAlive() > 0 && en7.getX() < 1000)
				graphics.drawImage(en7.getImage(), en7.getX(), en7.getY(), null);
			
			//Mob 3
			if (en8.isAlive() > 0 && en8.getX() < 1000)
				graphics.drawImage(en8.getImage(), en8.getX(), en8.getY(), null);
			if (en9.isAlive() > 0 && en9.getX() < 1000)
				graphics.drawImage(en9.getImage(), en9.getX(), en9.getY(), null);
			if (en10.isAlive() > 0 && en10.getX() < 1000)
				graphics.drawImage(en10.getImage(), en10.getX(), en10.getY(), null);
			if (en11.isAlive() > 0 && en11.getX() < 1000)
				graphics.drawImage(en11.getImage(), en11.getX(), en11.getY(), null);
			if (en12.isAlive() > 0 && en12.getX() < 1000)
				graphics.drawImage(en12.getImage(), en12.getX(), en12.getY(), null);
			
			//Mob 4
			if (en13.isAlive() > 0 && en13.getX() < 1000)
				graphics.drawImage(en13.getImage(), en13.getX(), en13.getY(), null);
			if (en14.isAlive() > 0 && en14.getX() < 1000)
				graphics.drawImage(en14.getImage(), en14.getX(), en14.getY(), null);
			if (en15.isAlive() > 0 && en15.getX() < 1000)
				graphics.drawImage(en15.getImage(), en15.getX(), en15.getY(), null);
			if (en16.isAlive() > 0 && en16.getX() < 1000)
				graphics.drawImage(en16.getImage(), en16.getX(), en16.getY(), null);
			if (en17.isAlive() > 0 && en17.getX() < 1000)
				graphics.drawImage(en17.getImage(), en17.getX(), en17.getY(), null);
			if (en18.isAlive() > 0 && en18.getX() < 1000)
				graphics.drawImage(en18.getImage(), en18.getX(), en18.getY(), null);
			if (en19.isAlive() > 0 && en19.getX() < 1000)
				graphics.drawImage(en19.getImage(), en19.getX(), en19.getY(), null);
			if (en20.isAlive() > 0 && en20.getX() < 1000)
				graphics.drawImage(en20.getImage(), en20.getX(), en20.getY(), null);
			
			//Mob 4 part 2
			if (en21.isAlive() > 0 && en21.getX() < 1000)
				graphics.drawImage(en21.getImage(), en21.getX(), en21.getY(), null);
			if (en22.isAlive() > 0 && en22.getX() < 1000)
				graphics.drawImage(en22.getImage(), en22.getX(), en22.getY(), null);
			if (en23.isAlive() > 0 && en23.getX() < 1000)
				graphics.drawImage(en23.getImage(), en23.getX(), en23.getY(), null);
			if (en24.isAlive() > 0 && en24.getX() < 1000)
				graphics.drawImage(en24.getImage(), en24.getX(), en24.getY(), null);
			if (en25.isAlive() > 0 && en25.getX() < 1000)
				graphics.drawImage(en25.getImage(), en25.getX(), en25.getY(), null);
			if (en26.isAlive() > 0 && en26.getX() < 1000)
				graphics.drawImage(en26.getImage(), en26.getX(), en26.getY(), null);
			
			//Final mob 5
			if (en27.isAlive() > 0 && en27.getX() < 1000)
				graphics.drawImage(en27.getImage(), en27.getX(), en27.getY(), null);
			if (en28.isAlive() > 0 && en28.getX() < 1000)
				graphics.drawImage(en28.getImage(), en28.getX(), en28.getY(), null);
			if (en29.isAlive() > 0 && en29.getX() < 1000)
				graphics.drawImage(en29.getImage(), en29.getX(), en29.getY(), null);
			if (en30.isAlive() > 0 && en30.getX() < 1000)
				graphics.drawImage(en30.getImage(), en30.getX(), en30.getY(), null);
			if (en31.isAlive() > 0 && en31.getX() < 1000)
				graphics.drawImage(en31.getImage(), en31.getX(), en31.getY(), null);
			if (en32.isAlive() > 0 && en32.getX() < 1000)
				graphics.drawImage(en32.getImage(), en32.getX(), en32.getY(), null);
			if (en33.isAlive() > 0 && en33.getX() < 1000)
				graphics.drawImage(en33.getImage(), en33.getX(), en33.getY(), null);
			if (en34.isAlive() > 0 && en34.getX() < 1000)
				graphics.drawImage(en34.getImage(), en34.getX(), en34.getY(), null);
			if (en35.isAlive() > 0 && en35.getX() < 1000)
				graphics.drawImage(en35.getImage(), en35.getX(), en35.getY(), null);
			if (en36.isAlive() > 0 && en36.getX() < 1000)
				graphics.drawImage(en36.getImage(), en36.getX(), en36.getY(), null);
			if (en37.isAlive() > 0 && en37.getX() < 1000)
				graphics.drawImage(en37.getImage(), en37.getX(), en37.getY(), null);
			if (en38.isAlive() > 0 && en38.getX() < 1000)
				graphics.drawImage(en38.getImage(), en38.getX(), en38.getY(), null);
			if (en39.isAlive() > 0 && en39.getX() < 1000)
				graphics.drawImage(en39.getImage(), en39.getX(), en39.getY(), null);
			if (en40.isAlive() > 0 && en40.getX() < 1000)
				graphics.drawImage(en40.getImage(), en40.getX(), en40.getY(), null);
			if (en41.isAlive() > 0 && en41.getX() < 1000)
				graphics.drawImage(en41.getImage(), en41.getX(), en41.getY(), null);
			if (en42.isAlive() > 0 && en42.getX() < 1000)
				graphics.drawImage(en42.getImage(), en42.getX(), en42.getY(), null);
			if (en43.isAlive() > 0 && en43.getX() < 1000)
				graphics.drawImage(en43.getImage(), en43.getX(), en43.getY(), null);
			if (en44.isAlive() > 0 && en44.getX() < 1000)
				graphics.drawImage(en44.getImage(), en44.getX(), en44.getY(), null);
			if (en45.isAlive() > 0 && en45.getX() < 1000)
				graphics.drawImage(en45.getImage(), en45.getX(), en45.getY(), null);
			if (en46.isAlive() > 0 && en46.getX() < 1000)
				graphics.drawImage(en46.getImage(), en46.getX(), en46.getY(), null);
			if (en47.isAlive() > 0 && en47.getX() < 1000)
				graphics.drawImage(en47.getImage(), en47.getX(), en47.getY(), null);
			if (en48.isAlive() > 0 && en48.getX() < 1000)
				graphics.drawImage(en48.getImage(), en48.getX(), en48.getY(), null);
			if (en49.isAlive() > 0 && en49.getX() < 1000)
				graphics.drawImage(en49.getImage(), en49.getX(), en49.getY(), null);
			if (en50.isAlive() > 0 && en50.getX() < 1000)
				graphics.drawImage(en50.getImage(), en50.getX(), en50.getY(), null);
		}
		
		ArrayList projectiles = Player.proList(); //Get projectile list
		for (int x = 0; x<projectiles.size(); x++) {
			
			Projectile p = (Projectile) projectiles.get(x);
			graphics.drawImage(p.pimg(), p.px(), p.py(), null);
			
		}
		
		//Player health and score indicator
		graphics.setFont(font);
		graphics.setColor(Color.white);
		if (player.begin == 1) {
			graphics.drawString("Health: " + player.health, 20, 40);
			if (player.isAlive() > 0 && (en47.isAlive() > 0 || en48.isAlive() > 0 || en49.isAlive() > 0 || en50.isAlive() > 0))
				graphics.drawString("Score: " + player.score, 800, 40);
		}
		else {
			graphics.setColor(Color.pink);
			graphics.drawString("Welcome to -insert name here-", 50,50);
			graphics.drawString("Oh no! K.C has stumbled upon a field of battle-ready gundams!", 50, 125);
			graphics.drawString("Help him pilot the ChaliceMobile and get through alive!", 50, 200);
			graphics.drawString("[Arrowkeys] to move - [Space] to fire", 50, 275);
			graphics.drawString("Don't get hit! ENEMY HIT = 50 points, KILL = 200", 50, 350);
			graphics.drawString("HAVE FUN! Press 'A' to begin", 50, 450);
		}
		
		//Gameover indicator
		graphics.setFont(end);
		graphics.setColor(Color.lightGray);
		if (player.isAlive() < 1 || en47.isAlive() < 1 && en48.isAlive() < 1 && en49.isAlive() < 1 && en50.isAlive() < 1) {
			endCounter++;
			if (endCounter >= 100) {
				graphics.drawString("GAME OVER", 100, 200);
				graphics.drawString("Score: " + player.score, 150, 350);
			}
		}
		
	} //End 2D graphics
	
	private class actionKey extends KeyAdapter { //Detect key press
		
		public void keyReleased(KeyEvent e) { //Key up method
			
			player.keyReleased(e);
			
		} //End method
		
		public void keyPressed(KeyEvent e) { //Key down method
			
			player.keyPressed(e);
			
		} //End method
		
	} //End private class

	@Override
	public void keyPressed(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void keyReleased(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	
}